/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.model;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Map;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import net.bioteam.appweb.TestConfig;
import net.bioteam.appweb.model.meta.Entry;
import net.bioteam.appweb.submit.DefaultCommandLineGenerator;

import junit.framework.TestCase;

public class LucyTester extends TestCase
{

	public LucyTester()
	{

	}

	public LucyTester(String name)
	{
		super(name);
	}

	protected void setUp() throws Exception
	{
		TestConfig.init();
		
		BeanshellProgramModifier modifier = new BeanshellProgramModifier();
		ProgramBuilder.modifiers.add(modifier);
	}

	protected void tearDown() throws Exception
	{
		TestConfig.shutdown();
	}

//	public void testTransform()
//	{
//		try
//		{
//			TransformerFactory tf = TransformerFactory.newInstance();
//
//			InputStream in = new FileInputStream("d:/cmdportal/cmdwork/xml/lucy.xml");
//			StreamSource ss = new StreamSource(in);
//
//			InputStream sin = Thread.currentThread().getContextClassLoader().getResourceAsStream("net/bioteam/appweb/model/program.xslt");
//			StreamSource xsls = new StreamSource(sin);
//
//			//ByteArrayOutputStream out = new ByteArrayOutputStream();
//			StreamResult sr = new StreamResult(System.err);
//
//			Transformer transformer = tf.newTransformer(xsls);
//			transformer.transform(ss, sr);
//		} catch (Exception e)
//		{
//			e.printStackTrace();
//			fail("Parsing failed");
//		}
//	}

	public void testLucyCtrl() throws Exception
	{
		ProgramBuilder.cache.remove("lucy");
		Program program = ProgramBuilder.getProgram("lucy");

		for (Parameter parameter : program.getAllParameters())
		{
			System.out.println(parameter.getName());
			
			if (!parameter.getCtrls().isEmpty())
			{
				for (Ctrl ctrl : parameter.getCtrls())
				{
					System.out.println(ctrl.getCode());
				}
			}
			if (parameter.getPrecond()!=null)
			{
				System.out.println(parameter.getPrecond().getCode());
			}
		}
	}

}
